<?php

namespace addons\shopro\controller\store;

use addons\shopro\exception\Exception;
use addons\shopro\controller\Base as ShoproBase;

/**
 * 不继承商家的 base
 */
class Apply extends ShoproBase
{

    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    public function info() {
        $this->success('商家申请', \addons\shopro\model\store\Apply::info());
    }

    /**
     * 商家分类 二级
     * 王猛 2022-1-24 14:45:06
     */
    public function storeCategoryInfo() {
        $res = db('category')->where(['type'=>'shop','pid'=>0,'status'=>'normal'])->order('weigh desc')->field('id,name,image')->select();
        if($res){
            foreach ($res as &$v){
                $v['sub'] = db('category')->where(['type'=>'shop','pid'=>$v['id'],'status'=>'normal'])->order('weigh desc')->field('id,name,image')->select();
            }
        }
        $data = [
            'cate'=>$res
        ];
        $this->success('', $data);
    }

    public function apply() {
        $params = $this->request->post();
        // 表单验证
        $this->shoproValidate($params, get_class(), 'apply');

        $order = \addons\shopro\model\store\Apply::apply($params);

        $this->success('商家申请提交成功', $order);
    }

}
